package com.taojiazheng.controller.user;

import com.taojiazheng.common.ResultResponse;
import com.taojiazheng.service.user.UserService;
import com.taojiazheng.so.user.UserinfoSo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 赵成林
 * @date 2017/11/23 20:07
 * 处理用户有关
 * 不包括登录注册
 */
@Controller
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 完善用户信息
     * @param userinfoSo
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "createUserInfo",method = RequestMethod.POST)
    public ResultResponse createUserInfo(@RequestBody UserinfoSo userinfoSo, HttpServletRequest request){
        String token = request.getHeader("token");
        userService. createUserInfo(userinfoSo,token);
        return new ResultResponse();
    }

    /**
     * 判断是否已经实名认证
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "isCreateInfo",method = RequestMethod.POST)
    public ResultResponse isCreateInfo(HttpServletRequest request){
        String token = request.getHeader("token");
        Boolean value = userService.isCreateUserInfo(token);
        return new ResultResponse(value);
    }

    /**
     * 取消实名认证
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "deleteUserInfo",method = RequestMethod.POST)
    public ResultResponse deleteUserInfo(HttpServletRequest request){
        String token = request.getHeader("token");
        userService.deleteUserInfo(token);
        return new ResultResponse();
    }
}
